import { CustomTableQuestion, InputQuestion, QuestionBase, SelectQuestion, TextQuestion, TitleQuestion } from '@/components/public-template';
import { Api as ApiStatement } from '@/config/api/watermark';

class HomeService {
  getQuestions(orgId, showType) {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'code',
        label: '编码',
        type: 'static',
        value: null,
        hidden: ['ADD'].includes(showType)
      }),
      new InputQuestion({
        key: 'name',
        label: '名称',
        required: true,
        value: null
      }),
      new SelectQuestion({
        key: 'watermarkingId',
        value: null,
        label: '电子水印',
        type: 'search',
        state: {
          url: ApiStatement.watermarkPage,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          params: {
            pageNumber: 1,
            pageSize: 999
          }
        }
      }),
      new TitleQuestion({
        label: '权限分配',
        state: { noShrink: true }
      }),
      new CustomTableQuestion({
        key: 'customTable',
        value: [],
        state: {
          grid: 24,
          fullLine: true,
          isAdd: true,
          default: {
            memberIds: [orgId],
            permission: 2
          },
          columns: [
            {
              width: '80px',
              title: '序号',
              type: 'index'
            },
            {
              width: '150px',
              title: '权限',
              key: 'permission',
              type: 'select',
              state: {
                filterName: 'DMS_FILE_PERMISSION'
              },
              required: true
            },
            {
              title: '用户',
              key: 'memberIds',
              type: 'custom',
              required: true
            }
          ]
        }
      })
    ];
    return questions;
  }

  getViewQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'code',
        label: '编码',
        value: null
      }),
      new TextQuestion({
        key: 'name',
        label: '名称',
        value: null
      }),
      new TextQuestion({
        key: 'watermarkingIdName',
        label: '电子水印',
        value: null
      }),
      new TitleQuestion({
        label: '权限分配',
        state: { noShrink: true }
      }),
      new CustomTableQuestion({
        key: 'customTable',
        value: [],
        state: {
          grid: 24,
          fullLine: true,
          columns: [
            {
              title: '序号',
              type: 'index'
            },
            {
              title: '权限',
              key: 'permission',
              type: 'dictionary',
              state: {
                filterName: 'DMS_FILE_PERMISSION'
              }
            },
            {
              title: '用户',
              key: 'memberNames'
            }
          ]
        }
      })
    ];
    return questions;
  }
}

export default new HomeService();
